package Com.itheima;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo {
    public static void main(String[] args) {
       test1();
       test2();
    }
    public static void test1()

    {
        Map<String, Double> map = new HashMap<>();
        map.put("张三", 99.0);
        map.put("李四", 88.0);
        map.put("王五", 77.0);
        map.put("赵六", 88.0);
        System.out.println(map);

        map.remove("张三");
        System.out.println(map);

        map.clear();
        System.out.println(map);

        boolean containsKey = map.containsKey("张三");
        System.out.println(containsKey);
        boolean containsValue = map.containsValue(99.0);
        System.out.println(containsValue);

        System.out.println(map.isEmpty());
        System.out.println(map.size());
        System.out.println(map);
    }

    public static void test2() {
        Map<String,Double> map= new HashMap<>();
        map.put("张三", 100.0);
        map.put("李四", 96.0);
        map.put("王五", 88.0);
        map.put("赵六", 78.0);
        //1.将map集合转换为set集合（将map中的key-value绑定成一个对象entry）
        Set<Map.Entry<String, Double>> entrySet = map.entrySet();
        //2.遍历set集合
        for (Map.Entry<String, Double> entry : entrySet) {
           //3.根据entry对象获取key和value
            String key = entry.getKey();
            Double value = entry.getValue();
            System.out.println(key+"--"+value);
          // map.forEach((key, value) -> System.out.println(key + "---" + value));
        }


    }
}
